<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="告知单编号" prop="adviseNo">
        <el-input
          v-model="queryParams.adviseNo"
          placeholder="请输入告知单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同流水号" prop="sequenceNumber">
        <el-input
          v-model="queryParams.sequenceNumber"
          placeholder="请输入合同流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同名称" prop="contractName">
        <el-input
          v-model="queryParams.contractName"
          placeholder="请输入合同名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同编号" prop="contractNo">
        <el-input
          v-model="queryParams.contractNo"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="M级" prop="security">
        <el-input
          v-model="queryParams.security"
          placeholder="请输入M级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="riskDate">
        <el-input
          v-model="queryParams.riskDate"
          placeholder="请输入日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="linkman">
        <el-input
          v-model="queryParams.linkman"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="contactInformation">
        <el-input
          v-model="queryParams.contactInformation"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="JS代表室" prop="representativeOffice">
        <el-input
          v-model="queryParams.representativeOffice"
          placeholder="请输入JS代表室"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目类别" prop="itemClassification">
        <el-input
          v-model="queryParams.itemClassification"
          placeholder="请输入项目类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同总金额" prop="totalAmount">
        <el-input
          v-model="queryParams.totalAmount"
          placeholder="请输入合同总金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品层级" prop="productHierarchy">
        <el-input
          v-model="queryParams.productHierarchy"
          placeholder="请输入产品层级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同甲方" prop="partyA">
        <el-input
          v-model="queryParams.partyA"
          placeholder="请输入合同甲方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同乙方" prop="partyB">
        <el-input
          v-model="queryParams.partyB"
          placeholder="请输入合同乙方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承制单位风险管理工作" prop="undertakeRiskManagement">
        <el-input
          v-model="queryParams.undertakeRiskManagement"
          placeholder="请输入承制单位风险管理工作"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总体风险评估——质量" prop="assessmentQuality">
        <el-input
          v-model="queryParams.assessmentQuality"
          placeholder="请输入总体风险评估——质量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总体风险评估——进度" prop="assessmentSchedule">
        <el-input
          v-model="queryParams.assessmentSchedule"
          placeholder="请输入总体风险评估——进度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总体风险评估——费用" prop="assessmentCost">
        <el-input
          v-model="queryParams.assessmentCost"
          placeholder="请输入总体风险评估——费用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总体风险评估——售后服务" prop="assessmentService">
        <el-input
          v-model="queryParams.assessmentService"
          placeholder="请输入总体风险评估——售后服务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="JDS意见" prop="representativeOfficeOpinion">
        <el-input
          v-model="queryParams.representativeOfficeOpinion"
          placeholder="请输入JDS意见"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拟制人" prop="fictitiousPerson">
        <el-input
          v-model="queryParams.fictitiousPerson"
          placeholder="请输入拟制人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:notification:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:notification:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:notification:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:notification:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="notificationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="告知单编号" align="center" prop="adviseNo" />
      <el-table-column label="合同流水号" align="center" prop="sequenceNumber" />
      <el-table-column label="合同名称" align="center" prop="contractName" />
      <el-table-column label="合同编号" align="center" prop="contractNo" />
      <el-table-column label="M级" align="center" prop="security" />
      <el-table-column label="日期" align="center" prop="riskDate" />
      <el-table-column label="联系人" align="center" prop="linkman" />
      <el-table-column label="联系方式" align="center" prop="contactInformation" />
      <el-table-column label="JS代表室" align="center" prop="representativeOffice" />
      <el-table-column label="合同类别" align="center" prop="contractType" />
      <el-table-column label="项目类别" align="center" prop="itemClassification" />
      <el-table-column label="合同总金额" align="center" prop="totalAmount" />
      <el-table-column label="产品层级" align="center" prop="productHierarchy" />
      <el-table-column label="合同甲方" align="center" prop="partyA" />
      <el-table-column label="合同乙方" align="center" prop="partyB" />
      <el-table-column label="承制单位风险管理工作" align="center" prop="undertakeRiskManagement" />
      <el-table-column label="总体风险评估——质量" align="center" prop="assessmentQuality" />
      <el-table-column label="总体风险评估——进度" align="center" prop="assessmentSchedule" />
      <el-table-column label="总体风险评估——费用" align="center" prop="assessmentCost" />
      <el-table-column label="总体风险评估——售后服务" align="center" prop="assessmentService" />
      <el-table-column label="JDS意见" align="center" prop="representativeOfficeOpinion" />
      <el-table-column label="拟制人" align="center" prop="fictitiousPerson" />
      <el-table-column label="风险通知单类型" align="center" prop="riskNoticeType" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="备注1" align="center" prop="note1" />
      <el-table-column label="备注2" align="center" prop="note2" />
      <el-table-column label="备注3" align="center" prop="note3" />
      <el-table-column label="备注4" align="center" prop="note4" />
      <el-table-column label="备注5" align="center" prop="note5" />
      <el-table-column label="备注6" align="center" prop="note6" />
      <el-table-column label="备注7" align="center" prop="note7" />
      <el-table-column label="备注8" align="center" prop="note8" />
      <el-table-column label="备注9" align="center" prop="note9" />
      <el-table-column label="备注10" align="center" prop="note10" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:notification:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:notification:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改风险告知单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="告知单编号" prop="adviseNo">
          <el-input v-model="form.adviseNo" placeholder="请输入告知单编号" />
        </el-form-item>
        <el-form-item label="合同流水号" prop="sequenceNumber">
          <el-input v-model="form.sequenceNumber" placeholder="请输入合同流水号" />
        </el-form-item>
        <el-form-item label="合同名称" prop="contractName">
          <el-input v-model="form.contractName" placeholder="请输入合同名称" />
        </el-form-item>
        <el-form-item label="合同编号" prop="contractNo">
          <el-input v-model="form.contractNo" placeholder="请输入合同编号" />
        </el-form-item>
        <el-form-item label="M级" prop="security">
          <el-input v-model="form.security" placeholder="请输入M级" />
        </el-form-item>
        <el-form-item label="日期" prop="riskDate">
          <el-input v-model="form.riskDate" placeholder="请输入日期" />
        </el-form-item>
        <el-form-item label="联系人" prop="linkman">
          <el-input v-model="form.linkman" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系方式" prop="contactInformation">
          <el-input v-model="form.contactInformation" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="JS代表室" prop="representativeOffice">
          <el-input v-model="form.representativeOffice" placeholder="请输入JS代表室" />
        </el-form-item>
        <el-form-item label="项目类别" prop="itemClassification">
          <el-input v-model="form.itemClassification" placeholder="请输入项目类别" />
        </el-form-item>
        <el-form-item label="合同总金额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入合同总金额" />
        </el-form-item>
        <el-form-item label="产品层级" prop="productHierarchy">
          <el-input v-model="form.productHierarchy" placeholder="请输入产品层级" />
        </el-form-item>
        <el-form-item label="合同甲方" prop="partyA">
          <el-input v-model="form.partyA" placeholder="请输入合同甲方" />
        </el-form-item>
        <el-form-item label="合同乙方" prop="partyB">
          <el-input v-model="form.partyB" placeholder="请输入合同乙方" />
        </el-form-item>
        <el-form-item label="承制单位风险管理工作" prop="undertakeRiskManagement">
          <el-input v-model="form.undertakeRiskManagement" placeholder="请输入承制单位风险管理工作" />
        </el-form-item>
        <el-form-item label="总体风险评估——质量" prop="assessmentQuality">
          <el-input v-model="form.assessmentQuality" placeholder="请输入总体风险评估——质量" />
        </el-form-item>
        <el-form-item label="总体风险评估——进度" prop="assessmentSchedule">
          <el-input v-model="form.assessmentSchedule" placeholder="请输入总体风险评估——进度" />
        </el-form-item>
        <el-form-item label="总体风险评估——费用" prop="assessmentCost">
          <el-input v-model="form.assessmentCost" placeholder="请输入总体风险评估——费用" />
        </el-form-item>
        <el-form-item label="总体风险评估——售后服务" prop="assessmentService">
          <el-input v-model="form.assessmentService" placeholder="请输入总体风险评估——售后服务" />
        </el-form-item>
        <el-form-item label="JDS意见" prop="representativeOfficeOpinion">
          <el-input v-model="form.representativeOfficeOpinion" placeholder="请输入JDS意见" />
        </el-form-item>
        <el-form-item label="拟制人" prop="fictitiousPerson">
          <el-input v-model="form.fictitiousPerson" placeholder="请输入拟制人" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注1" prop="note1">
          <el-input v-model="form.note1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注2" prop="note2">
          <el-input v-model="form.note2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注3" prop="note3">
          <el-input v-model="form.note3" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注4" prop="note4">
          <el-input v-model="form.note4" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注5" prop="note5">
          <el-input v-model="form.note5" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注6" prop="note6">
          <el-input v-model="form.note6" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注7" prop="note7">
          <el-input v-model="form.note7" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注8" prop="note8">
          <el-input v-model="form.note8" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注9" prop="note9">
          <el-input v-model="form.note9" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注10" prop="note10">
          <el-input v-model="form.note10" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNotification, getNotification, delNotification, addNotification, updateNotification } from "@/api/system/notification";

export default {
  name: "Notification",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 风险告知单表格数据
      notificationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        adviseNo: null,
        sequenceNumber: null,
        contractName: null,
        contractNo: null,
        security: null,
        riskDate: null,
        linkman: null,
        contactInformation: null,
        representativeOffice: null,
        contractType: null,
        itemClassification: null,
        totalAmount: null,
        productHierarchy: null,
        partyA: null,
        partyB: null,
        undertakeRiskManagement: null,
        assessmentQuality: null,
        assessmentSchedule: null,
        assessmentCost: null,
        assessmentService: null,
        representativeOfficeOpinion: null,
        fictitiousPerson: null,
        riskNoticeType: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询风险告知单列表 */
    getList() {
      this.loading = true;
      listNotification(this.queryParams).then(response => {
        this.notificationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        adviseNo: null,
        sequenceNumber: null,
        contractName: null,
        contractNo: null,
        security: null,
        riskDate: null,
        linkman: null,
        contactInformation: null,
        representativeOffice: null,
        contractType: null,
        itemClassification: null,
        totalAmount: null,
        productHierarchy: null,
        partyA: null,
        partyB: null,
        undertakeRiskManagement: null,
        assessmentQuality: null,
        assessmentSchedule: null,
        assessmentCost: null,
        assessmentService: null,
        representativeOfficeOpinion: null,
        fictitiousPerson: null,
        riskNoticeType: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加风险告知单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNotification(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改风险告知单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNotification(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNotification(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除风险告知单编号为"' + ids + '"的数据项？').then(function() {
        return delNotification(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/notification/export', {
        ...this.queryParams
      }, `notification_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
